<?php
namespace Amaze\Controller;
use Think\Controller;
use Home\Service\ToolService;
use Think\Model;
class ActivityController extends Controller{


	/**
	 * 魔术方法，设置默认处理机制
	 * @param String $method
	 * @param String $args
	 */
	public function __call($method, $args){
		if (method_exists('ActivityController', $method)){
			$this->$method;
		}else{
			$response['STATUS'] = "error";
			$response['ERRMSG'] = "no method";
			$response['RESULT'] = array();
			$this->ajaxReturn($response);
		}
	}

	/************************   教师基本信息 start      **************************/


	/**
	 * 加载活动资料
	 * */
	public function listUser(){
		$M = new Model();
		$query = "select * from activity";
		$activity= $M->query($query);
		$this->assign("activity",$activity);
		$this->theme('admin')->display('admin-table');
	}
	//计算老师讲过几次课
	//select count(*),teacher.id from activity,teacher where activity.teacher=teacher.id group by teacher.id
	//跳转至添加活动页面
	public function toAdd(){
		//查询教师表
		$te = M('teacher');
		$query = "select * from teacher";
		$js= $te->query($query);
		$this->assign("js",$js);
		$this->theme('admin')->display('admin-active');
	}
	//新增活动
	public function addActivity(){
		$active = I('param.');
		$active['status']=1;
		$active['create_time']=date("Y-m-d h:i:s");
		$res=$active=M('activity')->add($active);
		if(!empty($res)){
			$this->success('新增成功', 'listUser');
		}
		$this->error('新增失败');
	}
	//编辑活动
	public function editActivity(){
		$tid=I('param.tid');
		//查询教师表
		$te = M('teacher');
		$query = "select * from teacher";
		$js= $te->query($query);
		$this->assign("js",$js);
		$activity_table = M('activity');
		$activity_data = $activity_table->where(array("id"=>$tid))->find();
		//$department=M('department')->where(array("school"=>$teacher_data['school']))->select();
		if(!empty($activity_data)){
			$this->assign("activity",$activity_data);
			//$this->assign("department",$department);
			$this->theme('admin')->display('admin-editactive');
		}else{
			$this->error('教师不存在');
		}

	}
	//保存修改的活动
	public function updateActivity(){
		$activ = I('param.');
		$res=M('activity')->where(array("id"=>$activ['id']))->save($activ);
		if(!empty($res)){
			$this->success('修改成功', 'listUser');
		}
		$this->error('修改失败');
	}
	//统计报名学生数
	public function showStudents(){
		//$students=M('user');
		$students = new Model();
		$tid=I('param.tid');
		$st = $students->field('u.id,u.name,u.phone,u.login_time,u.create_time')
		->table('user as u,record as r')
		->where(array("r.activity"=>$tid,"r.user=u.id"))
		->select();
		//$st= $students->query($query);
		$this->assign("students",$st);
		
		$this->theme('admin')->display('admin-showstudents');
	}
	/**
		$stu = $students->where(array("r.activity"=>$tid,"r.user=u.id"))->find();
		$this->assign("s",$stu);
		$this->assign("experience",$res);
	 * 后台修改用户图片
	 * 调用地址 qiyiquan.com.cn/ekl2/Amaze/Teacher/changeTeachePic
	 * @param $tid
	 *
	 **/
	/************************   教师基本信息 end     **************************/

}
?>
